#include <iostream>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--){
		string src;
		cin>>src;
		char nowChar=src[0];
		int ans=0;
		for(int i=1;i<src.length();i++){
			if(src[i]==nowChar){
				ans++;
			}
			else{
				nowChar=src[i];
			}
		}
		cout<<ans<<endl;
	}
	return 0;
} 
